"use strict";
cc._RF.push(module, 'd94ecxxsUBBSaGP4GGcqFbG', 'vivoApi');
// scripts/engines/services/miniGameContent/vivo/vivoApi.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var miniApp_1 = require("../miniApp");
var gameConfig_1 = require("../../../configs/gameConfig");
var gameEngine_1 = require("../../../gameEngine");
var vivo = window['qg'];
var VivoApi = /** @class */ (function (_super) {
    __extends(VivoApi, _super);
    function VivoApi() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.m_appId = '105471298';
        _this.m_secret = '2a509613dc1ab0acc07d3feae0e617b1';
        _this.m_adUnitId = '938d34e48800444ca708eafe485ca1f6';
        _this.m_nAdIdList = ["82a8e6c680ec4b8d9fb960df74fc9bbb",
            "7f285298d43241fda503cb68468945de",
            "3a678c0c80f14a129589175c7c3bee90"];
        _this.m_BannerId = "80ff60d8c3444dd59731a584d11b1ff2";
        _this.m_BannerIdList = ["275dd2fa87c34ed7ae70ad09726663e0",
            "6fc862feba2f42fbac6862da13388359",
            "80ff60d8c3444dd59731a584d11b1ff2"];
        // protected m_InsertId: string = "mm9mdb790h929g3waj";
        //录屏管理器
        _this.m_gameRecorderManager = null;
        //录屏文件保存完地址
        _this.m_gameRecordVideoUrl = null;
        //视频广告组件
        _this.m_videoAd = null;
        //原生广告
        _this.m_nativeAd = null;
        _this.nowNAdId = 0;
        //banner广告
        _this.mowBanner = 0;
        _this.m_Bannerad = null;
        _this.bannerSuccese = true;
        _this.m_gameRecordTimeNow = 0;
        _this.m_localInBlockCity = false;
        return _this;
    }
    VivoApi.prototype.commitRank = function (rankId, score) {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, Promise.resolve(false)];
            });
        });
    };
    VivoApi.prototype.showRank = function (rankId) {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, Promise.resolve(false)];
            });
        });
    };
    VivoApi.prototype.operateGameLive = function () {
        // throw new Error("Method not implemented.");
    };
    VivoApi.prototype.getUserInfo = function (params) {
        vivo.getUserInfo(params);
    };
    VivoApi.prototype.showToast = function (params) {
        vivo.showToast(params);
    };
    VivoApi.prototype.showLoading = function (params) {
        vivo.showLoading(params);
    };
    VivoApi.prototype.hideLoading = function () {
        vivo.hideLoading();
    };
    /** 加载原生广告 */
    VivoApi.prototype.showNativeAd = function (successCallback, errorCallback, completeCallback) {
        var _this = this;
        this.m_nativeAd = vivo.createNativeAd({ posId: this.m_nAdIdList[this.nowNAdId] });
        this.m_nativeAd.load().then(function (res) {
            console.log("原生广告加载成功..." + res);
            _this.nowNAdId++;
            if (_this.nowNAdId == _this.m_nAdIdList.length) {
                _this.nowNAdId = 0;
            }
            completeCallback && completeCallback();
        }).catch(function (res) {
            console.log("原生广告加载失败..." + res);
            errorCallback(res);
            completeCallback && completeCallback();
        });
        this.m_nativeAd.onLoad(function (res) {
            _this.m_nAdlist = res.adList[0];
            _this.m_nativeAd.reportAdShow({ adId: _this.m_nAdlist.adId }); //原生广告曝光上报
            successCallback(_this.m_nAdlist);
            // console.log("------------  res.adList : " + res.adList);
            // // console.log("------------  res.adList.adId : " + res.adList.adId);  //错误使用方法
            // console.log("------------  res.adList[0].adId : " + res.adList[0].adId);
            // console.log("------------  res.adList[0].imgUrlList[0] : " + res.adList[0].imgUrlList[0]);
            // console.log("------------  this.m_nAdlist.imgUrlList[0] : " + this.m_nAdlist.imgUrlList[0]);
        });
    };
    /** 原生广告点击上报 */
    VivoApi.prototype.reportAdClickNativeAd = function () {
        this.m_nativeAd.reportAdClick({ adId: this.m_nAdlist.adId });
    };
    VivoApi.prototype.preCreateUnits = function () {
        this.CheckLocalToBlockCityList();
        // this.createRewardedVideovalidAppIdAd({ adUnitId: this.m_adUnitId });
        // this.m_gameRecorderManager = vivo.getGameRecorderManager();
    };
    VivoApi.prototype.loadAndShowPortalAd = function (successCallback, errorCallback, completeCallback) {
        //throw new Error("Method not implemented.");
    };
    VivoApi.prototype.onShareAppMessageGetReward = function (successCallback, errorCallback, completeCallback, isNeedModal) {
    };
    VivoApi.prototype.createMoreGameBtn = function () {
    };
    VivoApi.prototype.showInterstitialAd = function (onAdClose, onFailed) {
    };
    VivoApi.prototype.showBannerAD = function (node, successCallback, errorCallback, onCloseCallBack, setBannerPosition) {
        var _this = this;
        var _a = vivo.getSystemInfoSync(), screenWidth = _a.screenWidth, screenHeight = _a.screenHeight;
        var pos = setBannerPosition && setBannerPosition({ screenWidth: screenWidth, screenHeight: screenHeight }) || cc.v2(0, 0);
        // var targetBannerAdWidth = 200;
        if (this.m_Bannerad && !this.bannerSuccese) {
            this.m_Bannerad.destroy();
            this.m_Bannerad = null;
        }
        if (this.m_Bannerad) {
            this.m_Bannerad.show()
                .then(function () {
                successCallback && successCallback();
                console.log("---------------------Banner广告直接显示成功");
            })
                .catch(function (err) {
                errorCallback && errorCallback(err);
                console.log("---------------------Banner广告直接显示组件出现问题", JSON.stringify(err));
            });
            return;
        }
        this.bannerSuccese = true;
        if (this.m_Bannerad == null) {
            this.m_Bannerad = vivo.createBannerAd({
                posId: this.m_BannerIdList[this.mowBanner],
                adIntervals: 30,
                style: {
                    // width: targetBannerAdWidth,
                    // top: screenHeight - (targetBannerAdWidth / 16) * 9, // 根据系统约定尺寸计算出广告高度
                    left: pos.x,
                    top: pos.y,
                },
            }); //创建
        }
        this.m_Bannerad.onSize(function (size) {
            console.log(size.width, size.height, "------------banner长宽-----------");
            // this.m_Bannerad.style.top = size.height;//screenHeight - size.height;
            // this.m_Bannerad.style.left = size.width;//(screenWidth - size.width) / 2;
            // setBannerPosition && setBannerPosition({ x: this.m_Bannerad.style.left, y: this.m_Bannerad.style.top },
            //     { width: size.width, height: size.height });
        });
        this.m_Bannerad.onLoad(function () {
            if (node == null || !node.active || !node.isValid) {
                console.log("---------------------------------------------------------");
                return;
            }
            _this.mowBanner++;
            if (_this.mowBanner == _this.m_BannerIdList.length) {
                _this.mowBanner = 0;
            }
            _this.bannerSuccese = false;
            _this.m_Bannerad
                .show()
                .then(function () {
                successCallback && successCallback();
                console.log("---------------------Banner广告显示成功");
                _this.m_Bannerad.onClose(function () {
                    onCloseCallBack && onCloseCallBack();
                });
            })
                .catch(function (err) {
                errorCallback && errorCallback(err);
                console.log("---------------------Banner广告组件显示出现问题" + err.errCode + " :" + err.errMsg);
            });
        });
        this.m_Bannerad.onError(function (err) {
            _this.bannerSuccese = false;
            errorCallback && errorCallback(err);
            console.log("---------------------Banner广告加载错误,错误原因：" + err.errCode + " :" + err.errMsg);
        });
    };
    VivoApi.prototype.hideBanner = function () {
        if (null != this.m_Bannerad) {
            this.m_Bannerad.hide();
            console.log('---------------------banner广告隐藏完成');
        }
    };
    VivoApi.prototype.loadAndShowVideoAd = function (successCallback, errorCallback, completeCallback, reportAnalyticsExplain, videoIdPos) {
        var _this = this;
        if (videoIdPos === void 0) { videoIdPos = 0; }
        if (this.m_videoAd == null) {
            this.m_videoAd = vivo.createRewardedVideoAd({ adUnitId: this.m_adUnitId });
        }
        var onClose = function (res) {
            if (res && res.isEnded) {
                // 给予奖励
                successCallback();
                // O1HD.getManagers().soundMgr.setSoundEnabled(true);
            }
            else {
                //
                errorCallback('视频中途退出');
                // O1HD.getManagers().soundMgr.setSoundEnabled(true);
            }
            _this.m_videoAd.offClose(onClose);
            completeCallback && completeCallback();
            gameEngine_1.default.getManagers().soundMgr.setSoundEnabled(true);
            gameEngine_1.default.getManagers().soundMgr.playMusic("BGM1");
        };
        //
        this.m_videoAd.load().then(function () {
            gameEngine_1.default.getManagers().soundMgr.setSoundEnabled(false);
            _this.m_videoAd.show().then(function () {
                _this.m_videoAd.onClose(onClose);
                // O1HD.getManagers().soundMgr.setSoundEnabled(true);
                // O1HD.getManagers().soundMgr.playMusic("BGM1");
            }).catch(function (err) {
                errorCallback('视频显示错误  :' + JSON.stringify(err));
                _this.m_videoAd.offClose(onClose);
                completeCallback && completeCallback();
                gameEngine_1.default.getManagers().soundMgr.setSoundEnabled(true);
                gameEngine_1.default.getManagers().soundMgr.playMusic("BGM1");
            });
        }).catch(function (err) {
            errorCallback('视频加载错误  :' + JSON.stringify(err));
            _this.m_videoAd.offClose(onClose);
            completeCallback && completeCallback();
            gameEngine_1.default.getManagers().soundMgr.setSoundEnabled(true);
            gameEngine_1.default.getManagers().soundMgr.playMusic("BGM1");
        });
    };
    VivoApi.prototype.login = function (params) {
        vivo.login(params);
    };
    VivoApi.prototype.authorize = function (params) {
        params.success && params.success();
    };
    VivoApi.prototype.gameRecordStart = function (params, onStart) {
    };
    VivoApi.prototype.gameRecordStop = function () {
        return true;
    };
    VivoApi.prototype.isGameRecordOver = function () {
        return true;
    };
    VivoApi.prototype.shareGameRecordVideo = function (successCb, failCb) {
    };
    /**production    线上版
     development    测试版
     preview    预览版
     * */
    VivoApi.prototype.isProduction = function () {
        return VivoApi.isProduction();
    };
    VivoApi.prototype.isHaveShareVideo = function () {
        return true;
    };
    //判断是否合法APP-ID
    VivoApi.prototype.validAppId = function () {
    };
    VivoApi.prototype.reportAnalytics = function (EventKey, data) {
        console.log("vivo 发送埋点", EventKey, JSON.stringify(data));
    };
    VivoApi.prototype.clearMemory = function () {
    };
    VivoApi.prototype.shareAppMessage = function (args) {
    };
    VivoApi.prototype.createRewardedVideoAd = function (param) {
        // this.m_videoAd = vivo.createRewardedVideoAd(param);
    };
    /**production    线上版
     development    测试版
     preview    预览版
     * */
    VivoApi.isProduction = function () {
        return true;
    };
    VivoApi.prototype.PlayLastRecordSound = function (scale, successCb, errorCb) {
    };
    VivoApi.prototype.StartRecordSound = function () {
    };
    VivoApi.prototype.StopRecordSound = function (successCallback) {
    };
    VivoApi.prototype.addShortcut = function () {
        return Promise.resolve(false);
    };
    VivoApi.prototype.drawUrlImage = function (url, overCb) {
    };
    VivoApi.prototype.getShareVideoRank = function (sortType, successCb) {
    };
    VivoApi.prototype.showAddFavoriteGuide = function (successCallback, failCallback, completeCallback) {
    };
    VivoApi.prototype.showVideo = function (videoUrl) {
    };
    VivoApi.prototype.subscribeMessage = function (successCallback, failCallback, completeCallback) {
    };
    VivoApi.prototype.CheckLocalToBlockCityList = function () {
        var _this = this;
        gameEngine_1.default.getModules().gameHttpModule.getLocalPropertyInfo(function (res) {
            _this.m_localInBlockCity = gameConfig_1.default.IP_BLOCK_CITY.includes(res.city);
        }, function (err) {
            console.debug("-------获取区域信息错误", err);
        });
    };
    VivoApi.prototype.LocalInBlockCityList = function () {
        return this.m_localInBlockCity;
    };
    VivoApi.prototype.vibrate = function (type) {
    };
    VivoApi.prototype.showModal = function (params) {
    };
    VivoApi.prototype.navigateToMiniGame = function (appId, successCallback, failCallback) {
        console.error('#451102928 未实现');
    };
    return VivoApi;
}(miniApp_1.default));
exports.default = VivoApi;

cc._RF.pop();